<?php

use Johnm\Probackend\Former\Facades\Former;

$prefix = Config::get('probackend::config.prefix', 'admin');
$modules = Config::get('probackend::modules', array());

/**
 * =============================================================================
 * Edit form content
 * =============================================================================
 */
$edit_form_content = '<div class="text-center modal-frontdrop"><i class="icon-spinner3 spin block-inner"></i></div>';

$edit_form_content .='<div class="col-sm-4">';
$edit_form_content .= '<br><h5>' . Lang::get("probackend::administrator_group.form_create_information") . '</h5>';
$edit_form_content .= Former::text("title")
        ->label(Lang::get("probackend::administrator_group.model_group_title"))
        ->maxlength(255)
        ->value($title)
        ->required();

$edit_form_content .= Former::text("name")
        ->label(Lang::get("probackend::administrator_group.model_group_name"))
        ->maxlength(255)
        ->value($name)
        ->required();
$edit_form_content .='</div>';

$edit_form_content .= '<div class="col-sm-8">';
$edit_form_content .= '<br><h5>' . Lang::get("probackend::administrator_group.form_create_permistion") . '</h5>';
$edit_form_content .= '<table class="table">';
foreach ($modules as $moduleID => $module) {
    if ($moduleID === "dashboard")
        continue;
    $edit_form_content .= '<col/><col/>';
    $edit_form_content .= '<thead>';
    $edit_form_content .= '<tr class="active">';
    $edit_form_content .= '<th colspan=2>';
    $edit_form_content .= "Module " . $module['name'];
    $edit_form_content .= '</th>';
    $edit_form_content .= '</tr>';
    $edit_form_content .= '</thead>';


    $edit_form_content .= '<tbody>';

    foreach ($module['permistions'] as $permistionID => $permistionName) {
        $edit_form_content .= '<tr>';

        $edit_form_content .= '<td>';
        $edit_form_content .= $permistionName;
        $edit_form_content .= '</td>';

        $edit_form_content .= '<td>';
        $edit_form_content .= '<input type="checkbox" ' . (isset($permissions[$moduleID . '.' . $permistionID]) ? "checked" : "") . ' name="permissions[' . $moduleID . '.' . $permistionID . ']" value="1" class="switch-small model-create-form-switch">';
        $edit_form_content .= '</td>';

        $edit_form_content .= '</tr>';
    }

    $edit_form_content .= '<tbody>';
}
$edit_form_content .= '</table>';
$edit_form_content .='</div>';

$edit_form_content .= '<script>';
$edit_form_content .= "$(document).ready(function() {
    $('#crub-edit-model-dialog input[type=\'checkbox\']').bootstrapSwitch();
    $('#crub-edit-model-form').attr('action',MODULE_URL+'" . $id . "');
        
});";
$edit_form_content .= '</script>';

echo $edit_form_content;
?>

